package com.wanmait.wanmarecruit.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.wanmait.wanmarecruit.entity.ManageRolePermission;
import com.wanmait.wanmarecruit.mapper.ManageRolePermissionMapper;
import com.wanmait.wanmarecruit.service.ManagePermissionService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wanmait.wanmarecruit.mapper.ManagePermissionMapper;
import com.wanmait.wanmarecruit.entity.ManagePermission;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(rollbackFor = Exception.class)
public class ManagePermissionServiceImpl extends ServiceImpl<ManagePermissionMapper, ManagePermission> implements ManagePermissionService {
    @Resource
    private ManageRolePermissionMapper manageRolePermissionMapper;
    @Resource
    private ManagePermissionMapper managePermissionMapper;

    @Override
    public List<ManagePermission> findAllByRoleIds(List<Integer> roleIds) {
        LambdaQueryWrapper<ManageRolePermission> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(ManageRolePermission::getRoleId,roleIds);
        List<ManageRolePermission> manageRolePermissions = manageRolePermissionMapper.selectList(queryWrapper);
        if (manageRolePermissions.isEmpty())
        {
            return Collections.emptyList();
        }
        List<Integer> permIds = manageRolePermissions.stream().map(manageRolePermission -> manageRolePermission.getPermId()).collect(Collectors.toList());
        return managePermissionMapper.selectBatchIds(permIds);
    }
}
